How Linux Works by Brian Ward

How Linux Works by Brian Ward

Author:Brian Ward
Language: eng
Format: mobi, epub
Tags: COMPUTERS / Operating Systems / Linux
ISBN: 9781593270889
Publisher: No Starch Press
Published: 2009-08-20T03:00:00+00:00


badmath.o(.text+0x28): undefined reference to 'sin'

badmath.o(.text+0x36): undefined reference to 'pow'

The most important parts of these error messages are in bold. When the linker program examined the badmath.o object file, it could not find the math functions that appear in bold, and as a consequence, it could not create the executable. In this particular case, you might suspect that you forgot the math library because the missing functions refer to mathematical operations (sine and exponentiation).

Note

Undefined references do not always mean that you're missing a library. One of the program's object files could be missing in the link command. It's usually easy to differentiate between library functions and functions in your object files, though.

To fix this problem, you must first find the math library and then use the compiler's -l option to link against the library. As with include files, libraries are scattered throughout the system (/usr/lib is the system default location), though most libraries reside in a subdirectory named lib. For the preceding example, the math library file is libm.a (in /usr/lib), so the library name is m. Putting it all together, you would link the program like this:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.